<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/page/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">选择该项目经理</button>
    </div>
</script>


<script src="/page/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use('table', function () {
        var table = layui.table;

        table.render({
            elem: '#test'
            , url: '/admin/emp/manager'
            , toolbar: '#toolbarDemo'
            , cols: [[
                {type: 'radio'}
                , {field: 'empName', width: 100, title: '员工姓名', align: 'center'}
                , {field: 'empTel', width: 140, title: '联系方式', align: 'center'}
                , {field: 'empAddr', width: 150, title: '家庭住址', align: 'center'}
                , {field: 'empEmail', width: 150, title: '邮箱', align: 'center'}
            ]], parseData: function (res) {
                if (res.code == 200) {
                    res.code = 0
                }
                console.log(res)
                return {
                    "code": res.code,
                    "msg": res.msg,
                    "count": 1000,
                    "data": res.data,
                }
            }

        });
        var projectNo = window.location.href.split("?")[1].split("&")[0].split("=")[1]
        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            var $ = layui.$
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;  //获取选中行数据
                    console.log(data[0].empId)
                    $.ajax({
                        url: "/project/project/addManager",
                        data: {projectNo: projectNo, eId: data[0].empId},
                        type: "put",
                        dataType: "json",
                        success: function () {
                            layer.msg("选择项目经理成功，即将关闭页面");
                            setTimeout(function () {//设置定时器
                                parent.location.reload(true);//刷新父级页面
                                var index = parent.layer.getFrameIndex(window.name);
                                //获取当前弹窗的Id
                                parent.layer.close(index);
                            }, 3000);
                        }
                    })
                    break;
            }
            ;
        });
    });
</script>

</body>
</html>